﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using VirtualOrg.Helper;

namespace VirtualOrg.Web
{
    public partial class FormTaskList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Request.Cookies.AllKeys.Contains(SiteConstants.CookieName))
            {
                Response.Redirect("~/User/Login.aspx");
            }

            if (!IsPostBack)
            {
                GetTaskList();
            }
        }

        private void GetTaskList()
        {
            long userId = SiteHelper.DecryptSession(Request.Cookies[SiteConstants.CookieName].Value).UserID;
            using (DB.DbStoreDataContext dataContext = new DB.DbStoreDataContext())
            {
                if (ddlStatus.SelectedIndex == 0)
                {
                    GridTaskList.DataSource = dataContext.GetMyTaskList(userId, null);
                    DataTaskList.DataSource = dataContext.GetMyTaskList(userId, null);
                }
                else if (ddlStatus.SelectedIndex == 1)
                {
                    GridTaskList.DataSource = dataContext.GetMyTaskList(userId, true);
                }
                else if (ddlStatus.SelectedIndex == 2)
                {
                    GridTaskList.DataSource = dataContext.GetMyTaskList(userId, false);
                }

                GridTaskList.DataBind();
                DataTaskList.DataBind();
            }
        }

        protected void ddlStatus_SelectedIndexChanged(object sender, EventArgs e)
        {
            GetTaskList();
        }
    }
}